package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.*;
import cn.fintecher.pangolin.entity.mysql.QProcessApprover;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Objects;

/**
 * @Author wangxiangdong
 * @Description 信函打印request
 * @Date 2019/10/14 17:00
 **/
@Data
public class LetterPrintRequest {

    @ApiModelProperty("申调资料类型")
    private ApplyFileContent applyContent;

    @ApiModelProperty("操作状态")
    private ExportState exportState;

    @ApiModelProperty("批次号")
    private String batchNumber;

    @ApiModelProperty("客户姓名")
    private String personalName;

    @ApiModelProperty("身份证号码")
    private String certificateNo;

    @ApiModelProperty("委托方Id")
    private String principalId;

    @ApiModelProperty("委托方名称")
    private String principalName;

    @ApiModelProperty(notes = "申请日期开始")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date applyDateStart;

    @ApiModelProperty(notes = "申请日期结束")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date applyDateEnd;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        QProcessApprover processApprover = QProcessApprover.processApprover;
        booleanBuilder.and(processApprover.processFlowNode.processApplication.flowType.eq(FlowType.LETTER_PRINT_APPLY));
        booleanBuilder.and(processApprover.processFlowNode.processApplication.exportState.eq(this.exportState));
        if(Objects.nonNull(this.principalId)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.principalId.eq(this.principalId));
        }
        if(Objects.nonNull(this.personalName)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.personalName.eq(this.personalName));
        }
        if(Objects.nonNull(this.certificateNo)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.certificateNo.eq(this.certificateNo));
        }
        if(Objects.nonNull(this.batchNumber)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.batchNumber.eq(this.batchNumber));
        }
        if(Objects.nonNull(this.applyContent)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.applyContent.eq(this.applyContent));
        }
        if(Objects.nonNull(this.applyDateStart)) {
            booleanBuilder.and(processApprover.processFlowNode.processApplication.applyDate.goe(this.applyDateStart));
        }
        if(Objects.nonNull(this.applyDateEnd)){
            booleanBuilder.and(processApprover.processFlowNode.processApplication.applyDate.loe(this.applyDateEnd));
        }
        return booleanBuilder;
    }
}
